<template>
  <div class="app-container">
    <div class="search-area" v-show="showSearch">
      <el-form :model="queryParams" @submit.native.prevent ref="queryForm" size="small" :inline="true" class="clearfix"
        label-width="auto">
        <el-form-item label="陪玩类型" prop="type">
          <el-select v-model="queryParams.type" clearable placeholder="请选择陪玩类型">
            <el-option label="技术陪玩" :value="1" />
            <el-option label="娱乐陪玩" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item label="审核状态" prop="status">
          <el-select v-model="queryParams.status" clearable placeholder="请选择审核状态">
            <el-option label="待审核" :value="0" />
            <el-option label="审核通过" :value="1" />
            <el-option label="审核驳回" :value="2" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="main-content">
      <el-row :gutter="10" class="mb24">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
            v-hasPermi="['biz:applicationCard:add']">新增</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
            v-hasPermi="['biz:applicationCard:edit']">修改</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
            v-hasPermi="['biz:applicationCard:remove']">删除</el-button>
        </el-col>
        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
      </el-row>
      <el-table v-loading="loading" :data="applicationCardList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="申请人ID，关联user表" align="center" prop="userId" v-if="columns.userId.visible" />
        <el-table-column label="陪玩类型" align="center" prop="type" v-if="columns.type.visible">
          <template slot-scope="scope">
            <span v-if="scope.row.type === 1">技术陪玩</span>
            <span v-else-if="scope.row.type === 2">娱乐陪玩</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column label="审核状态" align="center" prop="status" v-if="columns.status.visible">'
          <template slot-scope="scope">
            <span v-if="scope.row.status === 0">待审核</span>
            <span v-else-if="scope.row.status === 1">审核通过</span>
            <span v-else-if="scope.row.status === 2">审核驳回</span>
            <span v-else>未知</span>
          </template>
        </el-table-column>
        <el-table-column label="服务定价" align="center" prop="price" v-if="columns.price.visible" />
        <el-table-column label="主玩游戏ID，关联game表" align="center" prop="gameId" v-if="columns.gameId.visible" />
        <el-table-column label="游戏段位/等级" align="center" prop="segment" v-if="columns.segment.visible" />
        <el-table-column label="段位证明图片URL" align="center" prop="proofImageUrl" v-if="columns.proofImageUrl.visible" />
        <el-table-column label="自我介绍/推广语" align="center" prop="introduction" v-if="columns.introduction.visible" />
        <el-table-column label="语音介绍URL" align="center" prop="voiceUrl" v-if="columns.voiceUrl.visible" />
        <el-table-column label="自定义标签，逗号分隔" align="center" prop="tags" v-if="columns.tags.visible" />
        <el-table-column label="审核管理员ID，关联admin_user表" align="center" prop="adminId" v-if="columns.adminId.visible" />
        <el-table-column label="审核备注" align="center" prop="auditRemark" v-if="columns.auditRemark.visible" />
        <el-table-column label="驳回理由" align="center" prop="rejectReason" v-if="columns.rejectReason.visible" />
        <el-table-column label="提交申请时间" align="center" prop="submitTime" v-if="columns.submitTime.visible" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.submitTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="auditTime" v-if="columns.auditTime.visible" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="是否生效：0-否 1-是" align="center" prop="isActive" v-if="columns.isActive.visible" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-tickets" @click="handleUpdate(scope.row, true)"
              v-hasPermi="['biz:applicationCard:query']">查看</el-button>
            <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
              v-hasPermi="['biz:applicationCard:edit']">修改</el-button>
            <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
              v-hasPermi="['biz:applicationCard:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
        @pagination="getList" />
    </div>



    <!-- 添加或修改自荐卡申请对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="850px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="auto" :disabled="disabled"
        :class="{ 'detail-disabled': disabled }">
        <el-form-item label="申请人ID，关联user表" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入申请人ID，关联user表" />
        </el-form-item>
        <el-form-item label="陪玩类型：1-技术陪玩 2-娱乐陪玩" prop="type">
          <el-input v-model="form.type" placeholder="请输入陪玩类型：1-技术陪玩 2-娱乐陪玩" />
        </el-form-item>
        <el-form-item label="审核状态：0-待审核 1-审核通过 2-审核驳回" prop="status">
          <el-input v-model="form.status" placeholder="请输入审核状态：0-待审核 1-审核通过 2-审核驳回" />
        </el-form-item>
        <el-form-item label="服务定价" prop="price">
          <el-input v-model="form.price" placeholder="请输入服务定价" />
        </el-form-item>
        <el-form-item label="主玩游戏ID，关联game表" prop="gameId">
          <el-input v-model="form.gameId" placeholder="请输入主玩游戏ID，关联game表" />
        </el-form-item>
        <el-form-item label="游戏段位/等级" prop="segment">
          <el-input v-model="form.segment" placeholder="请输入游戏段位/等级" />
        </el-form-item>
        <el-form-item label="段位证明图片URL">
          <file-upload v-model="form.proofImageUrl" :disabled="disabled" />
        </el-form-item>
        <el-form-item label="自我介绍/推广语" prop="introduction">
          <el-input v-model="form.introduction" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="语音介绍URL">
          <file-upload v-model="form.voiceUrl" :disabled="disabled" />
        </el-form-item>
        <el-form-item label="自定义标签，逗号分隔" prop="tags">
          <el-input v-model="form.tags" placeholder="请输入自定义标签，逗号分隔" />
        </el-form-item>
        <el-form-item label="审核管理员ID，关联admin_user表" prop="adminId">
          <el-input v-model="form.adminId" placeholder="请输入审核管理员ID，关联admin_user表" />
        </el-form-item>
        <el-form-item label="审核备注" prop="auditRemark">
          <el-input v-model="form.auditRemark" placeholder="请输入审核备注" />
        </el-form-item>
        <el-form-item label="驳回理由" prop="rejectReason">
          <el-input v-model="form.rejectReason" placeholder="请输入驳回理由" />
        </el-form-item>
        <el-form-item label="提交申请时间" prop="submitTime">
          <el-date-picker clearable v-model="form.submitTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择提交申请时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核时间" prop="auditTime">
          <el-date-picker clearable v-model="form.auditTime" type="date" value-format="yyyy-MM-dd"
            placeholder="请选择审核时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="是否生效：0-否 1-是" prop="isActive">
          <el-input v-model="form.isActive" placeholder="请输入是否生效：0-否 1-是" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer" v-if="!disabled">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listApplicationCard, getApplicationCard, delApplicationCard, addApplicationCard, updateApplicationCard } from "@/api/biz/applicationCard";

export default {
  name: "ApplicationCard",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 自荐卡申请表格数据
      applicationCardList: [],
      // 弹出层标题
      title: "",
      // 是否禁止表单填写
      disabled: false,
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        type: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 列信息
      columns: {
        userId: { label: "申请人ID，关联user表", visible: true },
        type: { label: "陪玩类型：1-技术陪玩 2-娱乐陪玩", visible: true },
        status: { label: "审核状态：0-待审核 1-审核通过 2-审核驳回", visible: true },
        price: { label: "服务定价", visible: true },
        gameId: { label: "主玩游戏ID，关联game表", visible: true },
        segment: { label: "游戏段位/等级", visible: true },
        proofImageUrl: { label: "段位证明图片URL", visible: true },
        introduction: { label: "自我介绍/推广语", visible: true },
        voiceUrl: { label: "语音介绍URL", visible: true },
        tags: { label: "自定义标签，逗号分隔", visible: true },
        adminId: { label: "审核管理员ID，关联admin_user表", visible: true },
        auditRemark: { label: "审核备注", visible: true },
        rejectReason: { label: "驳回理由", visible: true },
        submitTime: { label: "提交申请时间", visible: true },
        auditTime: { label: "审核时间", visible: true },
        isActive: { label: "是否生效：0-否 1-是", visible: true }
      },
      // 表单校验
      rules: {
        userId: [
          { required: true, message: "申请人ID，关联user表不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "陪玩类型：1-技术陪玩 2-娱乐陪玩不能为空", trigger: "change" }
        ],
        status: [
          { required: true, message: "审核状态：0-待审核 1-审核通过 2-审核驳回不能为空", trigger: "blur" }
        ],
        price: [
          { required: true, message: "服务定价不能为空", trigger: "blur" }
        ],
        gameId: [
          { required: true, message: "主玩游戏ID，关联game表不能为空", trigger: "blur" }
        ],
        segment: [
          { required: true, message: "游戏段位/等级不能为空", trigger: "blur" }
        ],
        introduction: [
          { required: true, message: "自我介绍/推广语不能为空", trigger: "blur" }
        ],
        submitTime: [
          { required: true, message: "提交申请时间不能为空", trigger: "blur" }
        ],
        isActive: [
          { required: true, message: "是否生效：0-否 1-是不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询自荐卡申请列表 */
    getList() {
      this.loading = true;
      listApplicationCard(this.formatParamsBatch(this.queryParams)).then(response => {
        this.applicationCardList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        type: null,
        status: 1,
        price: null,
        gameId: null,
        segment: null,
        proofImageUrl: null,
        introduction: null,
        voiceUrl: null,
        tags: null,
        adminId: null,
        auditRemark: null,
        rejectReason: null,
        submitTime: null,
        auditTime: null,
        isActive: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.disabled = false;
      this.title = "添加自荐卡申请";
      this.open = true;
    },
    /** 修改按钮操作 */
    handleUpdate(row, readOnly) {
      this.reset();
      const id = row.id || this.ids
      getApplicationCard(id).then(response => {
        this.form = response.data;
        this.disabled = readOnly ? true : false;
        this.title = readOnly ? "自荐卡申请详情" : "修改自荐卡申请";
        this.open = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateApplicationCard(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addApplicationCard(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除自荐卡申请编号为"' + ids + '"的数据项？').then(function () {
        return delApplicationCard(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('biz/applicationCard/export', {
        ...this.queryParams
      }, `applicationCard_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style scoped lang="scss">
.el-date-editor,
.el-select {
  width: 100%;
}
</style>
